﻿using Shumei.EFCore.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shumei.EFCore.SimpleService
{
    public class NewsService:BaseSimpleDAL<New>
    {
        public NewsService():base()
        {

        }
       /// <summary>
        /// 获取新闻列表
       /// </summary>
       /// <param name="page">页数</param>
       /// <param name="num">每页多少个</param>
       /// <returns></returns>
        public List<New> GetNewsList(int page,out int totalPage,int num = 10)
        {
            List<New> res;
            try
            {
                res = Entities.OrderBy(x => x.Id).Skip((page - 1) * 10).Take(num).ToList();
                totalPage = (Entities.Count()/num)+1;
            }
            catch
            {
                res = new List<New>();
                totalPage = 1;
            }
            return res;
        }

        public New GetNewDetail(int id)
        {
            
            try
            {
                return Entities.Find(id);
            }
            catch
            {
                return null;
            }
        }
    }
}
